<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<form action="#" method="post">
			<table border="1" cellspacing="0" cellpadding="10px" id="tableK">
				<tr>
					<th></th>
					<th>姓名</th>
					<th>性别</th>
					<th>年龄</th>
					<th>家庭住宅</th>
				</tr>
				<tr>
					<td><input type="checkbox" name="stu" id="" value="nan" /></td>
					<th>詹三</th>
					<th  id="sex">男</th>
					<th>18</th>
					<th>龙岩市</th>
				</tr>
				<tr>
					<td><input type="checkbox" name="stu" id="" value="nv" /></td>
					<th>詹四</th>
					<th id="sex">女</th>
					<th>18</th>
					<th>福安市</th>
				</tr>
				<tr>
					<td><input type="checkbox" name="stu" id="" value="nv" /></td>
					<th>詹五</th>
					<th  id="sex">女</th>
					<th>18</th>
					<th>海南市</th>
				</tr>
				<tr>
					<td><input type="checkbox" name="stu" id="" value="nv" /></td>
					<th>詹六</th>
					<th  id="sex">女</th>
					<th>18</th>
					<th>北京市</th>
				</tr>
				<tr>
					<td><input type="checkbox" name="stu" id="" value="nan" /></td>
					<th>詹七</th>
					<th  id="sex">男</th>
					<th>18</th>
					<th>上海市</th>
				</tr>
			</table>
			<input type="checkbox" id="checkkBoxAll"  onclick="onAllCheckk()" /> 全选
			<input type="button" name="" id="allf" value="选女" onclick="allF()"/>
			<input type="button" name="" id="allm" value="选女" onclick="allM1()"/>
			<input type="button" name="" id="" value="还原" onclick="alldele()" />
		</form>
		
	</body>
	<script type="text/javascript">
	var input1=document.getElementsByTagName('input');
	var checkbox1=document.getElementById('checkkBoxAll');
	
	//全选
		function onAllCheckk(){
			for (var i = 0; i < input1.length; i++) {
				input1[i].checked=checkbox1.checked;
			}
		}
		
	//全选女
	function allF(){
		for (var i = 0; i < input1.length; i++) {
			if (input1[i].value=='nv') {
				input1[i].checked=true;
			} else{
				input1[i].checked=false;
			}
		}
	}
	//全选男
	function allM1(){
		for (var i = 0; i < input1.length; i++) {
			if (input1[i].value=='nan') {
				input1[i].checked=true;
			} else{
				input1[i].checked=false;
			}
		}
	}
	//还原
	function alldele(){
		for (var i = 0; i < input1.length; i++) {
			input1[i].checked=false;
		}
	}
	
	</script>
</html>
